home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / MorphOS / Epic4_mos / share / epic / help / 7_docs / Programming < prev    next >
Encoding:
Text File  |  2002-10-28  |  4.1 KB  |  97 lines

  1. Programming in EPIC                                                         
  2.  
  3. This short (very short) document describes EPIC's programming language (some
  4. would argue it's but a scripting language) and how to use it.
  5.  
  6. The first thing to remember about scripts is that command characters are
  7. not required for commands!  In fact, their use is discouraged, as it only
  8. makes more work for the client when parsing the command.  There is, of
  9. course, an exception to this rule (but only one).  Because the client allows
  10. commands to be overloaded by aliases, there needs to be a way to access the
  11. original command.  This is done by giving the command character twice.  For
  12. instance:
  13.  
  14.    alias mode {
  15.       if ( (index(#&+ $0) == 0) || ([$0] == N) ) {
  16.          //mode $*
  17.       } {
  18.          //mode $C $*
  19.       }
  20.    }
  21.  
  22. The above alias overloads the builtin MODE command.  It first checks whether
  23. the first argument passed was a channel name or your own nickname.  If so,
  24. it executes the real MODE command using the arguments given.  Otherwise, it
  25. executes the real MODE command for the current channel.  Note that, because
  26. the command character can be changed, it is recommended that $K be used in
  27. lieu on a '/', as it will always represent the current command character:
  28.  
  29.    $K${K}mode $C $*
  30.  
  31. Certain characters have special meaning in scripts and inside certain
  32. commands that they don't necessarily have on the input line.  The semicolon
  33. (;), when used inside any {} command construct (from an alias, key binding,
  34. hook, timer action, etc.), acts as a command separator.  For example:
  35.  
  36.    alias blah {
  37.       on hook * echo hooked: $*;echo oops!
  38.    }
  39.  
  40. When the /blah alias is run, "oops!" will be displayed.  However, we didn't
  41. want that.  We wanted it to be displayed whenever the HOOK command was
  42. called.  The solution is the quote, or escape, the semicolon with the
  43. backslash:
  44.  
  45.    alias blah {
  46.       on hook * echo hooked: $*\;echo oops!
  47.    }
  48.  
  49. Naturally, the backslash (\) is another character with special meaning in
  50. scripts (but, again, not on the input line).  It quote, or escapes, the
  51. character immediately in front of it.  Escaping characters takes away any
  52. special meaning they might have (such as with semicolons, above).  One neat
  53. side effect from this is that it permits line-continuation in expressions:
  54.  
  55.    if ( foo == 1 && \
  56.         bar == 2 )      { ... }
  57.  
  58. Speaking of quoting characters, the client's quoting rules can be confusing.
  59. In general, everything works as described above; quote special characters to
  60. use them in text context.  However, the rules change when the client needs
  61. to parse a command more than once.  USERHOST is a classic example of this.
  62. Let's say we've created this alias:
  63.  
  64.    alias foo userhost $0 -cmd echo ($*)
  65.  
  66. That won't do at all, because both $expandos are parsed once, before the
  67. command is even executed, which isn't what we want.  So we need to do some
  68. quoting on the -cmd part:
  69.  
  70.    alias foo userhost $0 -cmd echo \($$*\)
  71.  
  72. Note that we quoted the '$' with the form '$$'.  This is a special expando
  73. that expands to a single '$'.  We could have escaped it with a backslash,
  74. but the $$ expando is faster.  Anyway, that alias won't work either.  Why?
  75. Because the parentheses cause the whole statement to be parsed twice, so
  76. we're right back where we started.  We need to add another level of quoting
  77. to the parentheses:
  78.  
  79.    alias foo userhost $0 -cmd echo \\\($$*\\\)
  80.  
  81. After the initial parse run, the parenthesis are still quoted, because '\\'
  82. expands to '\', and '\(' expands to '(', which together make '\('.  After the
  83. command is executed, the ECHO command is then parsed, this time correctly.
  84.  
  85. Other miscellaneous tips:
  86.  
  87.    1) Use variable and alias structures.
  88.    2) Indent your code consistently.  It will be easier to update later.
  89.    3) Comment your code.  So you'll know what you did a year from now.
  90.    4) Use serial numbered hooks whenever possible.
  91.    5) For server output, use the "end" message instead of a WAIT command.
  92.    6) Read the client documentation! :)
  93.  
  94. Refer to Section 5 of these helpfiles for information about specific
  95. commands.  Refer to Section 6 for the client's builtin functions.
  96.  
  97.